use actix_web::{HttpResponse, web};
use common::error::MyError;
use common::r::JsonResult;
use entity::accounts;
use model::accounts::{AccountsPage, CreateAccounts, RechargeBondsModel, ResetPasswordModel};
use model::auth::LoginModel;
use service::accounts::AccountsService;
use service::manager::accounts::AccountsManager;
use crate::controller::base::BaseController;

pub struct AccountsController {}

impl
BaseController<
    AccountsService,
    i32,
    accounts::Model,
    AccountsPage,
    CreateAccounts,
    accounts::Model,
    AccountsManager,
> for AccountsController
{}

impl AccountsController {

    // 重置密码
    pub async fn reset_password(form: web::Json<ResetPasswordModel>) -> Result<HttpResponse, MyError> {
        let res = AccountsService::reset_password(form.into_inner()).await?;
        Ok(HttpResponse::Ok().json(JsonResult::ok(res)))
    }
    //充值点券
    pub async fn recharge_bonds(form: web::Query<RechargeBondsModel>) -> Result<HttpResponse, MyError> {
        let res = AccountsService::recharge_bonds(form.into_inner()).await?;
        Ok(HttpResponse::Ok().json(JsonResult::ok(res)))
    }
    //重置创建角色数量
    pub async fn reset_create_role(params: web::Path<u32>) -> Result<HttpResponse, MyError> {
        let res = AccountsService::reset_create_role(params.into_inner()).await?;
        Ok(HttpResponse::Ok().json(JsonResult::ok(res)))
    }
    //设置最大角色栏位
    pub async fn set_max_role(params: web::Path<u32>) -> Result<HttpResponse, MyError> {
        let res = AccountsService::set_max_role(params.into_inner()).await?;
        Ok(HttpResponse::Ok().json(JsonResult::ok(res)))
    }
    //开启全部副本难度
    pub async fn open_dungeon(params: web::Path<u32>) -> Result<HttpResponse, MyError> {
        let res = AccountsService::open_dungeon(params.into_inner()).await?;
        Ok(HttpResponse::Ok().json(JsonResult::ok(res)))
    }

    //游戏账号登录
    pub async fn account_login(form: web::Json<LoginModel>) -> Result<HttpResponse, MyError> {
        let res = AccountsService::account_login(form.into_inner()).await?;
        Ok(HttpResponse::Ok().json(JsonResult::ok(res)))
    }


}